﻿using System.Collections.Generic;
using System.Reflection;
using System.Web.Mvc;
using SimpleInjector;
using SimpleInjector.Integration.Web.Mvc;
using YuYuKiCms.Bl.Interface;
using YuYuKiCms.Dal.Interface;
using YuYuKiCms.Framework.Interface;

namespace YuYuKiCms.Internet
{
    internal static class IoCConfig
    {
        internal static void RegisterIoC()
        {
            // Create the container as usual.
            var container = new Container();

            // Register your types, for instance:
            container.RegisterPackages(new List<Assembly>
            {
                Assembly.GetAssembly(typeof (IAccountBL)),
                Assembly.GetAssembly(typeof (IUserAccountRepository)),
                Assembly.GetAssembly(typeof (IUtil))
            });

            // This is an extension method from the integration package.
            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());

            // This is an extension method from the integration package as well.
            container.RegisterMvcAttributeFilterProvider();

            container.Verify();

            DependencyResolver.SetResolver(
                new SimpleInjectorDependencyResolver(container));
        }

        public static T GetInstantce<T>() where T : class
        {
            return DependencyResolver.Current.GetService<SimpleInjectorDependencyResolver>().Container.GetInstance<T>();
        }
    }
}